<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Vue中的JS动画</title>
    <script src="../lib/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<!--    添加颜色变化的动态效果-->
<!-- 入场动画：@before-enter为渲染之前的效果，enter为渲染完成时的效果，after-enter为渲染之后的效果-->
<!--出场动画：@before-leave 与 before-enter 类似-->
<div id="root">
    <transition
            name="fade"
            @before-enter="handleBeforeEnter"
            @enter="handleEnter"
            @after-enter="handleAfterEnter"
    >
        <div v-if="show">hello world</div>
    </transition>
    <button @click="handleClick">切换</button>
</div>
<script type="text/javascript">
    var vm = new Vue({
        el: "#root",
        data: {
            show: true
        },
        methods: {
            handleClick: function () {
                this.show = !this.show
            },
            handleBeforeEnter:function (el){
                el.style.color = 'red'
            },
            handleEnter:function (el,done){
                setTimeout(() =>{
                    el.style.color = 'yellow'
                },2000)
            },
            handleAfterEnter:function (el){
                el.style.color = "#000"
            }
        },
    });
</script>
<style type="text/css">
</style>
</body>
</html>
